
local SarfFix2_QuestLogLevel_GetQuestLogTitle_OldName = "SarfFix2_QuestLogLevel_GetQuestLogTitle_Saved";

function SarfFix2_QuestLogLevel_GetQuestLogTitle(...)
	local oldFunc = getglobal(SarfFix2_QuestLogLevel_GetQuestLogTitle_OldName);
	if ( type(oldFunc) ~= "function" ) then
		return nil;
	end
	local questLogTitleText, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, p1, p2, p3, p4, p5 = oldFunc(...);
	
	if ( displayLevels and questLogTitleText and level and level > 0 and not isHeader ) then
		if ( questTag == ELITE ) then
			questLogTitleText = "[" .. level .. "+] " .. questLogTitleText;
		elseif ( questTag == GROUP ) then
		  local n = tonumber(suggestedGroup);
		  if ( not n ) or ( n <= 0 ) then n = ""; end
			questLogTitleText = "[" .. level .. "G"..n.."] " .. questLogTitleText;
		elseif ( questTag == DUNGEON_DIFFICULTY3 ) then
			questLogTitleText = "[" .. level .. "E] " .. questLogTitleText;
		elseif ( questTag == DUNGEON_DIFFICULTY2 ) then
			questLogTitleText = "[" .. level .. "H] " .. questLogTitleText;
		elseif ( questTag == RAID ) then
			questLogTitleText = "[" .. level .. "R] " .. questLogTitleText;
		elseif ( questTag == PVP ) then
			questLogTitleText = "[" .. level .. "P] " .. questLogTitleText;
		elseif ( questTag == LFG_TYPE_DUNGEON ) then
			questLogTitleText = "[" .. level .. "D] " .. questLogTitleText;
		else
			questLogTitleText = "[" .. level .. "] " .. questLogTitleText;
		end
	end
	return questLogTitleText, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, p1, p2, p3, p4, p5;
end


function SarfFix2:QuestLogLevel_Initialize()
	local funcName = "GetQuestLogTitle";
	local newFuncName = "SarfFix2_QuestLogLevel_GetQuestLogTitle";
	local ignoreSecure = SarfFix2:GetSetting("overPatchQuestLevels");
	
	local oldFunc, oldFuncName = SarfFix2:HookFunction(funcName, newFuncName, true, ignoreSecure, true);
	local savedName = SarfFix2_QuestLogLevel_GetQuestLogTitle_OldName;
	if ( getglobal(savedName) ~= oldFunc ) then
		setglobal(savedName, oldFunc);
	end
end

SarfFix2:AddInitializer("QuestLogLevel_Initialize");
